/*
* @Author: Administrator
* @Date:   2017-07-24 18:26:20
* @Last Modified by:   Marte
* @Last Modified time: 2017-08-14 19:35:17
*/

var eleMenuOn = null;
var clMenuOn = "active";
String.prototype.temp = function(obj) {
  return this.replace(/\$\w+\$/gi, function(matchs) {
      var returns = obj[matchs.replace(/\$/g, "")];		
      return (returns + "") == "undefined"? "": returns;
  });
};
var eleMenus = $("#pageMenuWrap a").bind("click", function(event) {
  if (history.pushState) {
    	eleMenuOn && eleMenuOn.removeClass(clMenuOn);
    	eleMenuOn = $(this).parent().addClass(clMenuOn);
    	//eleListBox.html('<div class="cho_loading"></div>');
    	//$.ajax({
    		//url: this.href,
    		//dataType: "json",
    		//success: function(data) {
    			
    		//},
    		//error: function() {
    			
    		//}
    	//});
    	
			if($(this).attr("href")=="/ads_html/main.html"){
      	$("#content").html("main");
    	}
      if($(this).attr("href")=="/ads_html/promotionGroup.html"){
      	$("#content").load("html/promotionGroup/indexG.html");
    	}
      if($(this).attr("href")=="/ads_html/promotionPlan.html"){
        $("#content").load("html/promotionPlan/indexP.html");
      }
      if($(this).attr("href")=="/ads_html/originalityMM.html"){
        $("#content").load("html/originalityMM/createListSub.html");
      }
      if($(this).attr("href")=="/ads_html/acountInfo.html"){
        $("#content").load("html/acountInfo/acountSub.html");
      }
      if($(this).attr("href")=="/ads_html/acountFloor.html"){
        $("#content").load("html/acountFloor/acountFloorSub.html");
      }
      if($(this).attr("href")=="/ads_html/balanceInfo.html"){
        $("#content").load("html/balanceInfo/balanceSub.html");
      }
    	// // history处理
    	var title = "test-" + $(this).text().replace(/\d+$/, "");
    	document.title = title;
    	if (event && /\d/.test(event.button)) {			
    		history.pushState({ title: title }, title, this.href);
    	}
  }
  return false;
});
var fnHashTrigger = function(target) {
  var query = location.href, eleTarget = target || null;
  if (typeof query == "undefined") {
  	if (eleTarget = eleMenus.get(0)) {
  		history.replaceState(null, document.title, location.href) + location.hash;	
  		fnHashTrigger(eleTarget);
  	}
  } else {
  	eleMenus.each(function() {
  		if (eleTarget === null && this.href === query) {
  			eleTarget = this;
  		}
  	});
  	if (!eleTarget) {
  		history.replaceState(null, document.title, location.href);	
  		fnHashTrigger();
  	} else {			 
  		$(eleTarget).trigger("click");
  	}		
  }	
};
if (history.pushState) {
  window.addEventListener("popstate", function() {
  	fnHashTrigger();																
  });
  // 默认载入
  // fnHashTrigger();
}

 